/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package javalens.datageneration;

import javalens.astronomy.Event;
import javalens.astronomy.LightCurve;
import javalens.*;
import javalens.util.CalculationException;

/**
 *
 * @author Pierre
 */
public class RegularLightCurveGenerator implements LightCurveGenerator {

    private double startMinTe;
    private double startMaxTe;
    private double endMinTe;
    private double endMaxTe;
    private int nPoints;

    /** Creates a regular light curve, with slightly random start and end points
     * 
     * @param startMinTe The (usually negative) min start of the curve, in units of te
     * @param startMaxTe The (usually negative) max start of the curve, in units of te
     * @param endMinTe The (usually positive) min end of the curve, in units of te
     * @param endMaxTe The (usually positive) max end of the curve, in units of te
     * @param nPoints NUmber of points in this regular curve
     */
    public RegularLightCurveGenerator(double startMinTe, double startMaxTe, double endMinTe, double endMaxTe, int nPoints) {
        this.startMinTe = startMinTe;
        this.startMaxTe = startMaxTe;
        this.endMinTe = endMinTe;
        this.endMaxTe = endMaxTe;
        this.nPoints = nPoints;
    }

    /** Generates an evenly-spaced light curve plot
     * with random start and end position, based on event
     * centre and sides
     * 
     * @param event An event to generate the curve for
     */
    public LightCurve next(Event event) throws CalculationException {
        double centre = event.getTm();
        double scale = event.getTe();
        double startRange = startMaxTe - startMinTe;
        double endRange = endMaxTe - endMinTe;

        double start = centre + (startMinTe + Math.random() * startRange) * scale;
        double end = centre + (endMinTe + Math.random() * endRange) * scale;

        return LightCurve.createRegularTimeCurve(start, end, nPoints, event);
    }
}
